package assets_withdraw

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"
	"gitee.com/liuxuezhan/ar-platform/rpc-client/assetsClient/rpc"
	"github.com/zeromicro/go-zero/core/logx"
)

type AssetsWithDrawBankUpdateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// b端提现管理--银行字典--增加修改
func NewAssetsWithDrawBankUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AssetsWithDrawBankUpdateLogic {
	return &AssetsWithDrawBankUpdateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *AssetsWithDrawBankUpdateLogic) AssetsWithDrawBankUpdate(req *types.AssetsWithDrawBankUpdateReq) (resp *types.AssetsWithDrawBankUpdateRes, err error) {
	// todo: add your logic here and delete this line
	rpc_req := &rpc.UpdateWithDrawBankRequest{
		WithDrawBank: &rpc.WithDrawBank{
			Id:       req.Id,
			BankCode: req.BankCode,
			BankName: req.BankName,
			BankLogo: req.BankLogo,
			Status:   req.Status,
		},
	}

	// 发送请求
	rpc_resp, err := l.svcCtx.AssetsRpc.Config.BankUpdate(l.ctx, rpc_req)
	if err != nil {
		logx.Errorf("Call ModifyVipLevelInfos error: %v", err)
		return nil, err
	}

	// 处理请求返回的结果
	// 解析、组合数据
	resp = &types.AssetsWithDrawBankUpdateRes{}
	if rpc_resp.Data != nil {
		resp.WithDrawBank = types.WithDrawBank{
			Id:       rpc_resp.Data.Id,
			BankName: rpc_resp.Data.BankName,
			BankCode: rpc_resp.Data.BankCode,
			BankLogo: rpc_resp.Data.BankLogo,
			Status:   rpc_resp.Data.Status,
		}
	}
	return
}
